package com.caseor.minio.config;

import com.google.common.collect.Multimap;
import io.minio.CreateMultipartUploadResponse;
import io.minio.ListPartsResponse;
import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.errors.ErrorResponseException;
import io.minio.errors.InsufficientDataException;
import io.minio.errors.InvalidResponseException;
import io.minio.errors.XmlParserException;
import io.minio.messages.Part;
import lombok.SneakyThrows;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;

/**
 * @author Fu Kai
 * @since 20230408
 */

public class CustomizedMinioClient extends MinioClient {
  public CustomizedMinioClient(MinioClient client) {
    super(client);
  }

  /**
   * 创建分片上传请求
   *
   * @param bucketName       存储桶
   * @param region           区域
   * @param objectName       对象名
   * @param headers          消息头
   * @param extraQueryParams 额外查询参数
   */
  @SneakyThrows
  @Override
  public CreateMultipartUploadResponse createMultipartUpload(String bucketName, String region, String objectName, Multimap<String, String> headers, Multimap<String, String> extraQueryParams) throws NoSuchAlgorithmException, InsufficientDataException, IOException, XmlParserException, ErrorResponseException, InvalidResponseException {
    return super.createMultipartUpload(bucketName, region, objectName, headers, extraQueryParams);
  }

  /**
   * 完成分片上传，执行合并文件
   *
   * @param bucketName       存储桶
   * @param region           区域
   * @param objectName       对象名
   * @param uploadId         上传ID
   * @param parts            分片
   * @param extraHeaders     额外消息头
   * @param extraQueryParams 额外查询参数
   */
  @SneakyThrows
  @Override
  public ObjectWriteResponse completeMultipartUpload(String bucketName, String region, String objectName, String uploadId, Part[] parts, Multimap<String, String> extraHeaders, Multimap<String, String> extraQueryParams) throws NoSuchAlgorithmException, InsufficientDataException, IOException, XmlParserException, ErrorResponseException, InvalidResponseException {
    return super.completeMultipartUpload(bucketName, region, objectName, uploadId, parts, extraHeaders, extraQueryParams);
  }

  /**
   * 查询分片数据
   *
   * @param bucketName       存储桶
   * @param region           区域
   * @param objectName       对象名
   * @param uploadId         上传ID
   * @param extraHeaders     额外消息头
   * @param extraQueryParams 额外查询参数
   */
  @SneakyThrows
  @Override
  public ListPartsResponse listParts(String bucketName, String region, String objectName, Integer maxParts, Integer partNumberMarker, String uploadId, Multimap<String, String> extraHeaders, Multimap<String, String> extraQueryParams) throws NoSuchAlgorithmException, InsufficientDataException, IOException{
    return super.listParts(bucketName, region, objectName, maxParts, partNumberMarker, uploadId, extraHeaders, extraQueryParams);
  }
}
